<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>发送AJAX请求</title>
    <link rel="stylesheet" href="js/bootstrap.min.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/axios.min.js"></script>

    <script>
        window.onload=function(){
            new Vue({
                el: "#itany",
                data: {
                    uid: '',
                    user: {},
                },
                methods: {
                    send(){
                        axios({
                            methos:'get',
                            url:"user.json"
                        }).then(function(resp){
                            console.log(resp.data);
                        }).catch(resp => {
                            console.log("请求失败: "+ resp.status+resp.statusText)
                        });
                    },
                    sendGet(){
                        //axios.get('server.php?name=tom&age=23')  //请求url
                        axios.get('server.php',{
                            params:{
                                name :'alice',
                                age : 18
                            }
                        })
                        .then(resp => {
                            console.log(resp.data);
                        }).catch(err => {
                            console.log('请求失败: '+ err.status+','+err.statusText);
                        });
                    },
                    getUserByID(uid){
                        axios.get(`https://api.github.com/users/${uid}`)
                        .then(resp => {
                            this.user = resp.data;
                            console.log(this.user)
                        })
                    }
                }
            });

        }
    </script>
</head>
<body>
    <div id="itany">
        <button @click="send">发送AJAX请求</button>
        <button @click="sendGet">发送GET AJAX请求</button>
       
        <hr>
        <br/>
        GitHub ID: <input type="text" v-model="uid">
        <button @click="getUserByID(uid)">获取指定github账户信息并显示</button>
        <br/>
        用户： {{ user.id }}
        <br/>
         图片: <img :src="user.avatar_url">

        

    </div>
</body>
</html>
